import {observable as o, computed as c, action as a} from 'mobx';
import _ from 'lodash';
import axios from 'core/axios';
import RootStore from 'core/Store.js';
import request from 'core/request.js';
import Im from 'immutable';
import {browserHistory} from 'react-router';

class Store extends RootStore {
    constructor(args) {
        super(args);
    }

    @o visible = false;
    @o copy = false;
    @o confirmBtnText = $$.LN.CONFIRM;
    @o cancelBtnText = $$.LN.CANCEL;
    @o hideCancel = false;
    @o confirmBlue = false;
    @o tips = '';
    @o title = '';
    @o subTips = '';
    @o func = null;
    @o cancelFunc = null;
    @o showIcon = false;


    @a
    closeDialog(e) {
        e.preventDefault();
        e.stopPropagation();
        this.visible = false;
        if (typeof this.cancelFunc === 'function') {
            this.cancelFunc();
        }
        this.fire('confirmDialog:close');
    }

    @a
    confirmDialog(e) {
        e.preventDefault();
        if (this.copy) {
            document.getElementById('copy').click();
        }
        if (typeof this.func === 'function') {
            this.func();
        }
        this.visible = false;
    }

    will() {

    }

    mount() {
        this.on('confirmDialog:show', (data) => {
            this.visible = true;
            this.copy = data.copy || false;
            this.tips = data.tips || '';
            this.title = data.title || '';
            this.subTips = data.subTips || '';
            this.confirmBtnText = data.confirmBtnText || $$.LN.CONFIRM;
            this.cancelBtnText = data.cancelBtnText || $$.LN.CANCEL;
            this.func = data.func || null;
            this.cancelFunc = data.cancelFunc || null;
            this.hideCancel = data.hideCancel || false;
            this.confirmBlue = data.confirmBlue || false;
            this.showIcon = data.showIcon || false;
        });
        browserHistory.listen(() => {
            if (this.visible) {
                this.visible = false;
            }
        });
    }

}

export default Store;